cmake_minimum_required(VERSION 3.5)

project(camera_cross_view_base_opencv_gpu)

set(APP_NAME camera_cross_view_base_opencv_gpu)
set(THIRD_PATH_HOME_PATH /usr/local/athena/third_party)
set(ATHENA_ALGORITHM_PATH_HOME_PATH /usr/local/athena/athena_algorithm)

# set(CMAKE_EXE_STANSARD 14)
# set(CMAKE_CXX_COMPILIER "/usr/bin/g++")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-write-strings")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-g,-rpath -Wl,$ORIGIN")


IF (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
        link_directories("src/lib_x64")
        include_directories(
	/usr/local/cuda/include
	)
        link_directories(/usr/local/cuda/lib64)
ELSE()
        link_directories("bin/lib")
	#link_directories(bin/lib)
        include_directories(
	/usr/local/cuda/targets/aarch64-linux/include
)
        link_directories(/usr/local/cuda/targets/aarch64-linux/lib)
ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")

FIND_PACKAGE(OpenCV REQUIRED)
include_directories(
  ${OpenCV_INCLUDE_DIRS}
  )

link_directories(${OpenCV_LIBRARIES_DIRS})
message(STATUS "OpenCV_VERSION = ${OpenCV_VERSION}")

find_Package(gflags REQUIRED)
if(gflags_FOUND)
message("-- gflags found")
endif()

find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_NVCC_PLAGS ${CUDA_NVCC_PLAGS};-std=c++11;-g;-G;-gencode;arch=compute_30;code=sm_30)

find_path(TENSORRT_INCLUDE_DIR NvInfer.h
        HINTS ${TENSORRT_ROOT} ${CUDA_TOOLKIT_ROOT_DIR}
        PATH_SUFFIXES include)

option(ROS_ENABLE "option for ros enable" OFF)
if(ROS_ENABLE)
	add_definitions(-DROS_ENABLE)
	find_package(catkin REQUIRED COMPONENTS
		cv_bridge
		image_transport
		message_generation
		roscpp
		rospy
		sensor_msgs
		std_msgs
	)
	include_directories(
	${roscpp_INCLUDE_DIRS}
	${PROJECT_SOURCE_DIR}/../../../message/ros/devel/include
	${PROJECT_SOURCE_DIR}/../../../message/three_lane_message_lm/devel/include
	)
	# target_link_libraries(${catkin_LIBRARIES})
endif()


option(LCM_ENABLE "option for lcm enable" OFF)
if(LCM_ENABLE)
	add_definitions(-DLCM_ENABLE)
	include_directories(
	${PROJECT_SOURCE_DIR}/../../../message/lcm/src/athena
	)
endif()

option(DDS_ENABLE "option for dds enable" OFF)
if(DDS_ENABLE)
	add_definitions(-DDDS_ENABLE)
		include_directories(
	${PROJECT_SOURCE_DIR}/../message/dds/src/athena)
endif()

option(MDCLOG_ENABLE "option for dds enable" OFF)
option(GLOG_ENABLE "option for dds enable" OFF)
if(MDCLOG_ENABLE)
	add_definitions(-DMDCLOG_ENABLE)
elseif(GLOG_ENABLE)
	add_definitions(-DGLOG_ENABLE)
endif()

if (CMAKE_BUILD_TYPE MATCHES Debug)
    set(DEFAULT_COMPILE -std=c++14 -fpermissive -O0 -g3 -Wall -c -fmessage-length=0 -fPIC -fPIE -pie -fstack-protector-all -Wtrampolines)
elseif (CMAKE_BUILD_TYPE MATCHES Release)
    set(DEFAULT_COMPILE -std=c++14 -fpermissive -O3 -Wall -c -fmessage-length=0 -fPIC -fPIE -pie -fstack-protector-all -Wtrampolines)
endif()

add_compile_options(${DEFAULT_COMPILE})

macro(LISTSUBDIR result currentdir)
file(GLOB_RECURSE children LIST_DIRECTORIES true  ${currentdir}/*)
set(dirlist ${currentdir})
foreach(child ${children})
	if(IS_DIRECTORY ${child})
		list(APPEND dirlist ${child})
	endif()
endforeach()
set(${result} ${dirlist})
endmacro()

LISTSUBDIR(SOURCE_DIRS src)

include_directories(${SOURCE_DIRS})

include_directories(
    ${PROJECT_SOURCE_DIR}/..
    ${PROJECT_SOURCE_DIR}/../..
    ${PROJECT_SOURCE_DIR}/../../..
    ${PROJECT_SOURCE_DIR}/../../../..
)


include_directories(
	${THIRD_PATH_HOME_PATH}/arm64/include
	${THIRD_PATH_HOME_PATH}/arm64/include/eigen3
	common/athena
	common/tensorrt
    ${CUDA_TOOLKIT_ROOT_DIR}/include 

    ${TENSORRT_INCLUDE_DIR}
	)

link_directories(
	${THIRD_PATH_HOME_PATH}/arm64/lib/boost
    ${THIRD_PATH_HOME_PATH}/arm64/lib/lcm
	${THIRD_PATH_HOME_PATH}/arm64/lib/glog
	${THIRD_PATH_HOME_PATH}/arm64/lib/gflags
	${THIRD_PATH_HOME_PATH}/arm64/lib/protobuf
)

set(BOOST_LINK_LIBS "-lboost_system  -lboost_signals")

file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.cu src/*.cxx src/*.cpp src/*.cc) # ../../../common/*.c ../../../common/*.cxx ../../../common/*.cpp ../../../common/*.cc)

if(DDS_ENABLE)
find_package(fastcdr HINTS ${THIRD_PATH_HOME_PATH}/x64/lib/cmake/fastcdr)
find_package(fastrtps REQUIRED HINTS ${THIRD_PATH_HOME_PATH}/x64/lib/cmake/fastrtps)
file(GLOB_RECURSE DDS_SOURCE_FILES  ../message/dds/*.cxx)
endif()
	
add_executable(${APP_NAME}  ${SOURCE_FILES} ${DDS_SOURCE_FILES})
if(ROS_ENABLE)
	target_link_libraries(${APP_NAME}  ${roscpp_LIBRARIES} ${catkin_LIBRARIES})
endif()
if(LCM_ENABLE)
	target_link_libraries(${APP_NAME}  lcm glib-2.0)
endif()
if(DDS_ENABLE)
target_link_libraries(${APP_NAME}  fastrtps fastcdr)
endif()
target_link_libraries(${APP_NAME}
 ${CUDA_LIBRARIES} 
 ${TENSORRT_LIBRARY}
 ${OpenCV_LIBRARIES} 
 nvinfer
 nvinfer_plugin
 nvonnxparser
 #nvinfer_custom_plugin 
 nvparsers
 pthread 
 gflags
 glog
 protobuf
 dl 
 ${BOOST_LINK_LIBS}
)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
